// ============================================================================
//
// Copyright (C) 2006-2007 Dengues
//
// Google Group: http://groups.google.com/group/dengues
// QQ Group: 24885404
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// ============================================================================
package org.dengues.ui.web.browser.dom;

import org.dengues.ui.i18n.Messages;
import org.eclipse.swt.internal.ole.win32.IDispatch;

/**
 * All HTML element interfaces derive from this class. Elements that only expose the HTML core attributes are
 * represented by the base <code>HTMLElement</code> interface. These elements are as follows: HEAD special: SUB, SUP,
 * SPAN, BDO font: TT, I, B, U, S, STRIKE, BIG, SMALL phrase: EM, STRONG, DFN, CODE, SAMP, KBD, VAR, CITE, ACRONYM, ABBR
 * list: DD, DT NOFRAMES, NOSCRIPT ADDRESS, CENTER .
 * <p>
 * See also org.w3c.dom.html.HTMLElement.
 * 
 * @author jliu
 */
public class HTMLElement extends Node {

    public HTMLElement(IDispatch dispatch, DocumentContext context) {
        super(dispatch, context);
    }

    /**
     * Sets or retrieves the HTML between the start and end tags of the object.
     */
    public String getInnerHTML() {
        return getStringProperty("innerHTML"); //$NON-NLS-1$
    }

    /**
     * Sets or retrieves the object and its content in HTML.
     */
    public String getOuterHTML() {
        return getStringProperty("outerHTML"); //$NON-NLS-1$
    }

    /**
     * Sets or retrieves the text of the object.
     */
    public String getOuterText() {
        return getStringProperty("outerText"); //$NON-NLS-1$
    }

    /**
     * Sets or retrieves the text between the start and end tags of the object.
     */
    public String getInnerText() {
        return getStringProperty("innerText"); //$NON-NLS-1$
    }

    /**
     * Retrieves the calculated top position of the object relative to the layout or coordinate parent.
     */
    public int getOffsetTop() {
        return getIntProperty("offsetTop"); //$NON-NLS-1$
    }

    /**
     * Retrieves the calculated left position of the object relative to the layout or coordinate parent.
     */
    public int getOffsetLeft() {
        return getIntProperty("offsetLeft"); //$NON-NLS-1$
    }

    /**
     * Retrieves the width of the object relative to the layout or coordinate parent.
     */
    public int getOffsetWidth() {
        return getIntProperty("offsetWidth"); //$NON-NLS-1$
    }

    /**
     * Retrieves the height of the object relative to the layout or coordinate parent.
     */
    public int getOffsetHeight() {
        return getIntProperty("offsetHeight"); //$NON-NLS-1$
    }

    /**
     * Retrieves the distance between the offsetTop property and the true top of the client area.
     */
    public int getClientTop() {
        return getIntProperty("clientTop"); //$NON-NLS-1$
    }

    /**
     * Retrieves the distance between the offsetLeft property and the true left side of the client area.
     */
    public int getClientLeft() {
        return getIntProperty("clientLeft"); //$NON-NLS-1$
    }

    /**
     * Retrieves the width of the object including padding, but not including margin, border, or scroll bar.
     */
    public int getClientWidth() {
        return getIntProperty("clientWidth"); //$NON-NLS-1$
    }

    /**
     * Retrieves the height of the object including padding, but not including margin, border, or scroll bar
     */
    public int getClientHeight() {
        return getIntProperty("clientHeight"); //$NON-NLS-1$
    }

    /** Retrieves the scrolling height of the object. */
    public int getScrollHeight() {
        return getIntProperty("scrollHeight"); //$NON-NLS-1$
    }

    /** Retrieves the scrolling width of the object. */
    public int getScrollWidth() {
        return getIntProperty("scrollWidth"); //$NON-NLS-1$
    }

    /**
     * Sets or retrieves the distance between the top of the object and the topmost portion of the content currently
     * visible in the window.
     */
    public int getScrollTop() {
        return getIntProperty("scrollTop"); //$NON-NLS-1$
    }

    /**
     * Sets or retrieves the distance between the left edge of the object and the leftmost portion of the content
     * currently visible in the window.
     */
    public int getScrollLeft() {
        return getIntProperty("scrollLeft"); //$NON-NLS-1$
    }

    /**
     * Retrieves a reference to the container object that defines the offsetTop and offsetLeft properties of the object.
     */
    public HTMLElement getOffsetParent() {
        IDispatch disp = getDispatchProperty("offsetParent"); //$NON-NLS-1$
        if (disp != null) {
            return (HTMLElement) context.getNode(disp);
        }
        return null;
    }
}
